import { BaseService } from "@cool-midway/core";
import { InjectEntityModel } from "@midwayjs/typeorm";
import { Repository } from "typeorm";
import { UserFavoriteEntity } from "../entity/favorite";
import { Inject, Provide } from "@midwayjs/core";
import { AddFavoriteDTO } from "../dto/favorite";
import { Context } from "@midwayjs/koa";

@Provide()
export class UserFavoriteService extends BaseService {
    @InjectEntityModel(UserFavoriteEntity)
    userFavoriteEntity: Repository<UserFavoriteEntity>;

    @Inject()
    ctx: Context;

    async add(dto: AddFavoriteDTO) {
        return await this.userFavoriteEntity.save({
            userId: this.ctx.user.id,
            relatedId: dto.relatedId,
            relatedType: dto.relatedType,
            relatedName: dto.relatedName,
        });
    }
}